package com.choichumgming.rentcat.config;



import com.choichumgming.rentcat.common.config.RentcatMvcConfig;
import com.choichumgming.rentcat.service.UmsMemberFeignApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import javax.annotation.Resource;


@Configuration
@EnableWebMvc
public class UmsWebMvcConfig extends RentcatMvcConfig {
    @Resource
    private UmsMemberFeignApi umsMemberFeignApi;

    @Bean
    public UserDetailsService userDetailsService() {
        //获取登录用户信息
        return new UserDetailsServiceImpl();
    }

    class UserDetailsServiceImpl implements UserDetailsService {
        @Override
        public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
            return (UserDetails) umsMemberFeignApi.loadUserByUsername(username).getData();
        }
    }

}